package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.ShoppingModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import org.xutils.image.ImageOptions;
import org.xutils.x;

/**
 * Created by asus on 2017/12/20.
 */

public class SpecialSubAdapter extends RecyclerArrayAdapter<ShoppingModel.SpecialListBean.SubListBean> {
    private int type;
    private static final int ITEM_TYPE0 = 0;
    private static final int ITEM_TYPE1 = 1;
    private static final int ITEM_TYPE2 = 2;
    private static final int ITEM_TYPE3 = 3;
    private static final int ITEM_TYPE4 = 4;
    private static final int ITEM_TYPE5 = 5;
    private static final int ITEM_TYPE6 = 6;
    private static final int ITEM_TYPE7 = 7;

    private Context mContext;

    public SpecialSubAdapter(Context context, int type) {
        super(context);
        this.type = type;
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        SpecialSubViewHolder viewHolder;
        switch (type) {
            case ITEM_TYPE0:
                //模板1与模板6上
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type1);
                break;
            case ITEM_TYPE1:
                //模板2 与模板3左侧
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type2);
                break;
            case ITEM_TYPE2:
                //模板三右侧
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type1);
                break;
            case ITEM_TYPE3:
                //模板4上
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type4);
                break;
            case ITEM_TYPE4:
                //模板4下
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type4);
                break;
            case ITEM_TYPE5:
                //模板5 与模板6下
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type5);
                break;
            case ITEM_TYPE6:
                // 模板7上
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type7);
                break;
            case ITEM_TYPE7:
                // 模板7下
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type5);
                break;
            default:
                viewHolder = new SpecialSubViewHolder(parent, R.layout.item_shopping_special_type1);
                break;
        }
        return viewHolder;
    }

    private class SpecialSubViewHolder extends BaseViewHolder<ShoppingModel.SpecialListBean.SubListBean> {
        private TextView tvSpecialTitle;
        private TextView tvSpecialDec1;
        private TextView tvSpecialDec2;
        private ImageView ivSpecialImg;


        public SpecialSubViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            tvSpecialTitle = $(R.id.tv_special_title);
            tvSpecialDec1 = $(R.id.tv_special_descrtion1);
            tvSpecialDec2 = $(R.id.tv_special_descrtion2);
            ivSpecialImg = $(R.id.iv_special_img);


        }


        @Override
        public void setData(ShoppingModel.SpecialListBean.SubListBean data) {
            super.setData(data);
            if (data.getTitle()!=null&&data.getTitle().length()>=5){
                tvSpecialTitle.setText(data.getTitle().substring(0,3)+"...");
            }
            else {
                tvSpecialTitle.setText(data.getTitle());
            }
            if (data.getDescription1()!=null&&data.getDescription1().length()>=5){
                tvSpecialDec1.setText(data.getDescription1().substring(0,4)+"...");
            }
            else {
                tvSpecialDec1.setText(data.getDescription1());
            }

            if (data.getDescription2()!=null&&data.getDescription2().length()>5){
                tvSpecialDec2.setText(data.getDescription2().substring(0,4)+"...");
            }
            else {
                tvSpecialDec2.setText(data.getDescription2());
            }


            x.image().bind(ivSpecialImg,data.getLogo()+"-src", new ImageOptions.Builder()
                    .setFailureDrawableId(R.mipmap.icon_goods_list_default)
                    .setLoadingDrawableId(R.mipmap.icon_goods_list_default)
                    .build());
            switch (type) {
                case ITEM_TYPE0:
                    //模板1与模板6上
                    break;
                case ITEM_TYPE1:
                    //模板2 与模板3左侧
                    tvSpecialDec1.setTextColor(mContext.getResources().getColor(R.color.appThemeSub2TitleColor));
                    break;
                case ITEM_TYPE2:
                    //模板三右侧
                    if (getLayoutPosition() == 0) {
                        tvSpecialDec1.setTextColor(mContext.getResources().getColor(R.color.appThemeSub2TitleColor));
                    } else {

                        tvSpecialDec1.setTextColor(mContext.getResources().getColor(R.color.shopping_blue));
                    }

                    break;
                case ITEM_TYPE3:
                    //模板4上
                    tvSpecialDec1.setTextColor(mContext.getResources().getColor(R.color.shopping_blue));
                    break;
                case ITEM_TYPE4:
                    //模板4下
                    tvSpecialDec1.setTextColor(mContext.getResources().getColor(R.color.shopping_blue));

                    break;
                case ITEM_TYPE5:
                    //模板5 与模板6下
                    break;
                case ITEM_TYPE6:
                    // 模板7上
                    if (getLayoutPosition() == 0) {
                        tvSpecialTitle.setTextColor(mContext.getResources().getColor(R.color.shopping_yellow));
                    } else {
                        tvSpecialTitle.setTextColor(mContext.getResources().getColor(R.color.black));
                    }
                    break;
                case ITEM_TYPE7:
                    // 模板7下
                    tvSpecialDec1.setTextColor(mContext.getResources().getColor(R.color.appThemeSub2TitleColor));
                    break;
            }
        }
    }
}
